package com.sgb.kjwl.view.ui.adapter.self.publish;

import android.content.Context;
import android.view.View;

import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ItemLeaseMemberStateBinding;
import com.sgb.kjwl.databinding.ItemLeaseStateBinding;
import com.sgb.kjwl.model.entity.self.LeaseMemberListEntity;
import com.sgb.kjwl.model.entity.self.LeaseStateEntity;
import com.sgb.kjwl.view.ui.activity.house.LeaseHousesActivity;
import com.sgb.kjwl.view.ui.activity.self.lease.LeaseMemberPriceAddActivity;
import com.sgb.kjwl.view.ui.activity.self.lease.LeaseMemberPriceListActivity;
import com.sgb.kjwl.view.ui.activity.self.publish.CarPublishActivity1;
import com.sgb.kjwl.view.ui.activity.self.publish.DevicePublishActivity;
import com.sgb.kjwl.view.ui.activity.self.publish.LeaseFactoryActivity;
import com.sgb.kjwl.view.ui.activity.self.publish.LeaseFarmActivity;
import com.sgb.kjwl.view.ui.activity.self.publish.LeaseLandActivity;
import com.sgb.kjwl.view.ui.activity.self.publish.LeaseMachineActivity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;
import com.swgk.core.util.DateUtils;

import java.util.List;

public class LeaseMemberStateAdapter extends BaseRecycleAdapter<LeaseMemberListEntity> {

    public LeaseMemberStateAdapter(Context context, List<LeaseMemberListEntity> datas) {
        super(context, R.layout.item_lease_member_state, datas);
    }

    @Override
    public void convert(ItemViewHolder holder, final LeaseMemberListEntity entity) {
        holder.setBinding(BR.viewModel, entity);
        ItemLeaseMemberStateBinding binding = (ItemLeaseMemberStateBinding) holder.getmBinding();
        binding.tvTime.setText(DateUtils.stampToDay(entity.getVipPriceTime()));

        if ("1".equals(entity.getType())) {
            binding.tvType.setText("机械租赁");
        } else if ("2".equals(entity.getType())) {
            binding.tvType.setText("设备租赁");
        } else if ("3".equals(entity.getType())) {
            binding.tvType.setText("车辆租赁");
        } else if ("4".equals(entity.getType())) {
            binding.tvType.setText("房产租赁");
        } else if ("5".equals(entity.getType())) {
            binding.tvType.setText("土地租赁");
        } else if ("6".equals(entity.getType())) {
            binding.tvType.setText("工厂租赁");
        } else if ("7".equals(entity.getType())) {
            binding.tvType.setText("农机租赁");
        }

        //会员价状态，1:生效中;2:已失效
        if ("1".equals(entity.getVipPriceStatus())) {
            binding.tvStop.setVisibility(View.VISIBLE);
            binding.tvSetting.setVisibility(View.GONE);
            binding.ivStatus.setImageResource(R.mipmap.ic_lease_vip_price_state1);
        } else if ("2".equals(entity.getVipPriceStatus())) {
            binding.tvStop.setVisibility(View.GONE);
            binding.tvSetting.setVisibility(View.VISIBLE);
            binding.ivStatus.setImageResource(R.mipmap.ic_lease_vip_price_state2);
        }
        //再次设置
        binding.tvSetting.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                LeaseMemberPriceAddActivity.start(binding.getRoot().getContext(),entity.getNo(),entity.getType());
            }
        });
        //结束会员价
        binding.tvStop.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (itemCallBack != null) {
                    itemCallBack.onStop(entity.getNo(), entity.getType());
                }
            }
        });
        //详情
        binding.tvDetailPrice.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (itemCallBack != null) {
                    itemCallBack.onDetail(entity.getNo(), entity.getType());
                }
            }
        });
    }

    public void setItemCallBack(ItemCallBack itemCallBack) {
        this.itemCallBack = itemCallBack;
    }

    private ItemCallBack itemCallBack;

    public interface ItemCallBack {
        void onStop(String id, String type);

        void onDetail(String id, String type);
    }


}
